﻿using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Markup;
using FSquirrel.Helpers;
using GalaSoft.MvvmLight.Threading;
using FileSquirrel.Logic;
using FSquirrel.Properties;
using System;

namespace FSquirrel
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private Indexer indexer;
        static App()
        {
            DispatcherHelper.Initialize();
            FrameworkElement.LanguageProperty.OverrideMetadata(
               typeof(FrameworkElement),
               new FrameworkPropertyMetadata(
                   XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            if (e.Args.Any())
            {
                foreach (var arg in e.Args)
                {
                    switch (arg.ToUpper().Replace("/", ""))
                    {
                        case "QR":
                            ArgumentsHelper.QuickRefresh = true;
                            break;
                    }
                }
            }


            if (ArgumentsHelper.QuickRefresh)
            {

                FileSquirrel.Logic.XSD.UserSettings _userSettings = Reader.UserSettings;
                _Indexer.GatherFiles(_userSettings.Category, null);
                Application.Current.Shutdown();
            }
            else
            {
                MainWindow mw = new FSquirrel.MainWindow();
                mw.Show();
            }


            base.OnStartup(e);

        }

        public Indexer _Indexer
        {
            get { return indexer ?? (indexer = new Indexer(Settings.Default.LibraryName, Settings.Default.LibraryDir)); }
        }
    }
}